package com.huawei.hwid.f;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ProviderInfo;
import com.huawei.hwid.core.d.b.e;

public class d {
    private final PackageManager a;

    public enum a {
        ENABLED,
        DISABLED,
        NOT_INSTALLED
    }

    public d(Context context) {
        this.a = context.getPackageManager();
    }

    public a a(String str) {
        try {
            if (this.a.getApplicationInfo(str, 0).enabled) {
                return a.ENABLED;
            }
            return a.DISABLED;
        } catch (NameNotFoundException e) {
            return a.NOT_INSTALLED;
        }
    }

    public int b(String str) {
        try {
            PackageInfo packageInfo = this.a.getPackageInfo(str, 16);
            if (packageInfo != null) {
                return packageInfo.versionCode;
            }
            return 0;
        } catch (NameNotFoundException e) {
            e.b("PackageManagerHelper", "NameNotFoundException", true);
            return 0;
        } catch (Exception e2) {
            e.b("PackageManagerHelper", "Exception  ", true);
            return 0;
        }
    }

    public boolean a(String str, String str2) {
        try {
            PackageInfo packageInfo = this.a.getPackageInfo(str, 8);
            if (packageInfo == null || packageInfo.providers == null) {
                return false;
            }
            for (ProviderInfo providerInfo : packageInfo.providers) {
                if (str2.equals(providerInfo.authority)) {
                    return true;
                }
            }
            return false;
        } catch (NameNotFoundException e) {
            return false;
        }
    }
}
